home *** CD-ROM | disk | FTP | other *** search
-
-
- ' ============================
- ' Interface from VB to Btrieve
- ' ============================
- Sub CallBtrv (ByVal OpCod As Integer, ByVal FileNo As Integer, ByVal KeyNo As Integer)
- Dim LockType As Integer ' record lock type
- Static DupFlg As Integer ' duplicates flag
- Dim NoData As Integer ' key only flag (bias of 50)
- Dim KVal As String ' key value sent to Btrieve
- LockType = (OpCod \ 100) * 100 ' extract lock type
- OpCod = OpCod - LockType ' adjust to actual op code
- NoData = 0 ' assume we want data in GET operations
- If OpCod > 54 And OpCode < 74 Then ' do we want just the key in GET operations?
- NoData = 50 ' yes
- OpCod = OpCode - NoData ' adjust to actual op code
- End If
- If OpCod < 0 Or OpCod > 49 Then ' is this a valid op code?
- BStatus = BE_INVALID_OPCOD
- GoTo Fatal
- End If
- Select Case OpCod
- Case 0 ' Open a file
- KVal = Path + FileName(FileNo) ' put the filename in the key buffer
- GoSub MakeCall ' do it
- If BStatus = BE_FILENOTFOUND Then ' file not found?
- Exit Sub
- ElseIf BStatus = BE_FILE_LOCKED Then ' is file locked?
- Beep
- MsgBox "File" + Str$(FileNo) + " is locked by another user. Try again later!", 16, "File open error"
- ElseIf BStatus = BE_PERMISSION Then ' network permission error?
- Beep
- MsgBox "Permission error", 16, "File open error"
- ElseIf BStatus <> BE_OK Then ' any other error
- GoTo Fatal
- End If
- Case 1 ' Close a file
- GoSub MakeCall ' do it
- If BStatus <> BE_OK Then ' error closing the file?
- GoTo Fatal
- End If
- Case 2 ' Insert
- KVal = Space$(128) ' create key buffer
- GoSub LoadBuf ' put the data into Btrieve's buffer
- GoSub MakeCall ' do it
- ' check for errors
- If BStatus <> BE_OK And BStatus <> BE_CONFLICT And BStatus <> BE_READ_OUT_TRANS And BStatus <> BE_RECORD_LOCKED Then
- GoTo Fatal
- End If
- KeyVal = Left$(KVal, KeyLen(FileNo, KeyNo)) ' return the key
- Case 3 ' Update
- KVal = KeyVal + Space$(128 - Len(KeyVal)) ' create the key buffer
- GoSub LoadBuf ' put the data into Btrieve's buffer
- GoSub MakeCall ' do it
- ' check for errors
- If BStatus <> BE_OK And BStatus <> BE_CONFLICT And BStatus <> BE_READ_OUT_TRANS And BStatus <> BE_RECORD_LOCKED Then
- GoTo Fatal
- End If
- KeyVal = Left$(KVal, KeyLen(FileNo, KeyNo)) ' return the key
- Case 4 ' Delete
- GoSub MakeCall ' do it
- ' check for errors
- If BStatus <> BE_OK And BStatus <> BE_CONFLICT And BStatus <> BE_READ_OUT_TRANS And BStatus <> BE_RECORD_LOCKED Then
- GoTo Fatal
- End If
- Case 5 To 13 ' GET operations
- KVal = KeyVal + Space$(128 - Len(KeyVal)) ' create the key buffer
- GoSub MakeCall ' do it
- If BStatus = BE_EOF Then ' end of file?
- KeyVal = ""
- ' check for other errors?
- ElseIf BStatus <> BE_OK And BStatus <> BE_KEYNOTFOUND And BStatus <> BE_RECORD_LOCKED Then
- GoTo Fatal
- End If
- If Not NoData Then ' if we want the data
- GoSub ExtractBuf ' put it in the file's data buffer
- End If
- If BStatus = BE_OK Then ' if operations successfil
- KeyVal = Left$(KVal, KeyLen(FileNo, KeyNo)) ' return the key value
- End If
- Case 14 ' Create
- KVal = Path + FileName(FileNo) ' put the filename into the key buffer
- GoSub MakeCall ' do it
- Case 19 To 21 ' Begin, End and Abort Transaction
- GoSub MakeCall ' just do it
- Case 22 ' Get position
- GoSub MakeCall ' do it
- ' return the position in the key value
- KeyVal = Left$(BtrvBuf.buffer, KeyLen(FileNo, KeyNo))
- Case 23 ' Get direct
- BtrvBuf.buffer = KeyVal ' put the position in Btrieve's data buffer
- KVal = Space$(128) ' create a key buffer
- GoSub MakeCall ' do it
- If BStatus = BE_OK Then ' if successful
- GoSub ExtractBuf ' put the data into the file's data buffer
- End If
- KeyVal = Left$(KVal, KeyLen(FileNo, KeyNo)) ' extract the key value
- Case 24, 33 To 35 ' Step direct, step first, last, previous
- GoSub MakeCall ' do it
- If BStatus = BE_OK Then ' if successful
- GoSub ExtractBuf ' put the data into the file's data buffer
- End If
- Case 25 ' Stop Btrieve
- GoSub MakeCall ' do it
- Case 27 ' Unlock
- If KeyNo = 1 Then ' unlock a multiple record lock?
- BtrvBuf.buffer = KeyVal ' put the position into the data buffer
- End If
- GoSub MakeCall ' do it
- Case 28 ' Reset
- GoSub MakeCall
- KeyVal = "" ' return null
- Case 48 ' No of Recs
- OpCod = 15 ' set op code for Btrieve's use
- GoSub fStat ' do a Btrieve status
- KeyVal = Str$(cvl(Mid$(BtrvBuf.buffer, 7, 4))) ' return the number of records as a string in KeyVal
- Case 49 ' Toggle DupFlg
- DupFlg = Not (DupFlg) ' toggle duplicates flag
- End Select
- Exit Sub
-
- MakeCall:
- ' call Btrieve
- BStatus = BtrCall(OpCod + NoData + LockType, PosBlk(FileNo), BtrvBuf, Len(BtrvBuf), KVal, Len(KVal), KeyNo)
- Return
- ExtractBuf:
- ' put Btrieve's data buffer into the files data buffer
- ' modify this section for your files
- Select Case FileNo
- Case 0
- LSet ChartRec = BtrvBuf
- End Select
- Return
- LoadBuf:
- ' put the file's data buffer into Btrieve's data buffer
- ' modify this section for your files
- Select Case FileNo
- Case 0
- LSet BtrvBuf = ChartRec
- End Select
- Return
- fStat: ' status op code
- KVal = Space$(128)
- GoSub MakeCall
- Return
- Fatal: ' process any errors
- If BStatus = BE_DUPKEY And DupFlg Then ' duplicates ok?
- Return ' continue
- End If
- ' show error
- Beep
- MsgBox "Btrieve error" + Str$(BStatus) + " for file " + FileName(FileNo), 16, "Btrieve error"
- End Sub
-
- ' This function takes a 4 byte string representation of
- ' a 4 byte long integer and creates the integer
- ' This function is included is other Basics but was
- ' omitted in VB
- Function cvl (mkl As String) As Long
- cvl = Asc(Left$(mkl, 1)) + Asc(Mid$(mkl, 2, 1)) And 255 + (Asc(Mid$(mkl, 3, 1)) + (Asc(Right$(mkl, 1)) And 255) And 65535)
- End Function
-
-